package com.wave.wavesystem.common.util;


import wave.common.functional.OneParamFunction;
import wave.common.pojo.entity.KV;


import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 夕下风波
 * @date 2025-02-03 10:47
 * @description
 */
public class EnumUtil {

    public static <T, R, V> T getByEquals(List<T> list, OneParamFunction<T, R> valueFunction, V value) {
        if (Func.isEmpty(list)) return null;
        for (T enumItem : list) {
            boolean equals = valueFunction.apply(enumItem).equals(value) || valueFunction.apply(enumItem) == value;
            if (equals) {
                return enumItem;
            }
        }
        return null;
    }


    public static <T, V, R> List<KV<T, V>> getKVAll(List<R> list, OneParamFunction<R, T> keyFunction, OneParamFunction<R, V> valueFunction) {
        return list.stream()
                .map(item -> new KV<>(keyFunction.apply(item), valueFunction.apply(item)))
                .collect(Collectors.toList());
    }
}
